<!DOCTYPE html><html><head>
<title>tepam - Tcl's Enhanced Procedure and Argument Manager</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'tepam_introduction.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2009-2013, Andreas Drollinger
   -->
<!-- tepam.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
&#124; <a href="../../../../toc.html">Main Table Of Contents</a>
&#124; <a href="../../../toc.html">Table Of Contents</a>
&#124; <a href="../../../../index.html">Keyword Index</a>
&#124; <a href="../../../../toc0.html">Categories</a>
&#124; <a href="../../../../toc1.html">Modules</a>
&#124; <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">tepam(n) 0.5.0 tcllib &quot;Tcl's Enhanced Procedure and Argument Manager&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>tepam - An introduction into TEPAM, Tcl's Enhanced Procedure and Argument Manager</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">OVERVIEW</a></li>
<li class="doctools_section"><a href="#section3">PROCEDURE DECLARATION</a></li>
<li class="doctools_section"><a href="#section4">PROCEDURE HELP</a></li>
<li class="doctools_section"><a href="#section5">PROCEDURE CALL</a></li>
<li class="doctools_section"><a href="#section6">INTERACTIVE PROCEDURE CALLS</a></li>
<li class="doctools_section"><a href="#section7">FLEXIBLE ARGUMENT DIALOG BOX</a></li>
<li class="doctools_section"><a href="#see-also">See Also</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This document is an informal introduction into TEPAM, the Tcl's Enhanced Procedure and Argument Manager. Detailed information to the TEPAM package is provided in the <em>tepam::procedure</em> and <em>tepam::argument_dialogbox</em> reference manuals.</p>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">OVERVIEW</a></h2>
<p>This package provides a new Tcl procedure declaration syntax that simplifies the implementation of procedure subcommands and the handling of the different types of procedure arguments like flags or switches, options, unnamed arguments, optional and mandatory options and arguments, default values, etc. Procedure declarations can be enriched with detailed information about the procedure and its arguments. This information is used for the following purposes:</p>
<p>First of all, a preamble is added in front of the body of a procedure that is declared with TEPAM. This preamble calls an argument manager that that uses the provided information to check the validity of the argument types and values before the procedure body is executed. Then, the information is used to generate help and usage texts if requested, or to generate clear error message in case an argument validation fails. The information also allows generating automatically graphical forms that allows an interactive definition of all arguments, in case a procedure is called interactively. And finally, the additional information helps self-commenting in a clean way the declaration of a procedure and of all its arguments.</p>
<p>The graphical form generator that creates the necessary argument specification forms for the interactive procedure calls is also available for other purposes than for procedure argument specifications. It allows creating code efficiently complex parameter entry forms that are usable independently from TEPAM's new procedure definition method.</p>
<p>Here is a short overview about all major TEPAM features:</p>
<ul class="doctools_itemized">
<li><p>New self-documenting procedure declaration syntax: The additional information to declare properly a procedure has not to be provided with additional statements, but can be added in a natural syntax directly into the procedure header.</p></li>
<li><p>Easy way to specify subcommands: A subcommand is declared like a procedure, simply with a procedure name composed by a base name followed by a subcommand name. Sub-subcommands are created identically using simply procedure names composed by 3 words.</p></li>
<li><p>Flexible usage of flags (switches), options (named arguments) and unnamed arguments. Option names are optionally automatically completed.</p></li>
<li><p>Support for default values, mandatory/optional options and arguments, choice lists, value ranges, multiple usable options/arguments.</p></li>
<li><p>Choice of a <em>named arguments first, unnamed arguments later</em> procedure calling style (typical for Tcl commands) or of an <em>unnamed arguments first, named arguments later</em> procedure calling style (typical for Tk commands).</p></li>
<li><p>In case the <em>named arguments first, unnamed arguments later</em> style (Tcl) is selected:  Clear separation between options and arguments via the &quot;--&quot; flag. The unnamed arguments can optionally be accessed as options (named arguments).</p></li>
<li><p>Automatic type and value check before the procedure body is executed, taking into account validation ranges, choice lists and custom validation commands. Generation of clear error message if necessary.</p></li>
<li><p>Many predefined types exist (integer, boolean, double, color, file, font, ...). Other application specific types can easily be added.</p></li>
<li><p>Automatic help and usage text generation if a procedure is called with the <i class="arg">-help</i> flag.</p></li>
<li><p>Automatic generation of an interactive argument definition form, in case a procedure is called with the <i class="arg">-interactive</i> flag.</p></li>
<li><p>Procedure calls can be logged which is useful to get for interactively called procedures the command call lines.</p></li>
<li><p>Powerful and code efficient generation of complex parameter definition forms.</p></li>
</ul>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">PROCEDURE DECLARATION</a></h2>
<p>TEPAM's procedure declaration syntax is simple and self-explaining. Instead of declaring a procedure with the Tcl key word <b class="cmd"><a href="../../../../index.html#proc">proc</a></b>, a procedure is declared with the TEPAM command <b class="cmd"><a href="../../../../index.html#procedure">procedure</a></b> which takes as <b class="cmd"><a href="../../../../index.html#proc">proc</a></b> also 3 arguments: The procedure name, the procedure header and the procedure body.</p>
<p>The following example declares the subcommand <b class="cmd"><a href="../../../../index.html#message">message</a></b> of the procedure <b class="cmd">display</b>. This command has several named and unnamed arguments:</p>
<pre class="doctools_example"><b class="cmd"><a href="tepam_procedure.html">tepam::procedure</a></b> {display message} {
   -return            -
   -short_description &quot;Displays a simple message box&quot;
   -description       &quot;This procedure allows displaying a configurable message box.&quot;
   -args {
      {-mtype -default Warning -choices {Info Warning Error} -description &quot;Message type&quot;}
      {-font -type font -default {Arial 10 italic} -description &quot;Message text font&quot;}
      {-level -type integer -optional -range {1 10} -description &quot;Message level&quot;}
      {-fg -type color -default black -description &quot;Message color&quot;}
      {-bg -type color -optional -description &quot;Background color&quot;}
      {-no_border -type none -description &quot;Use a splash window style (no border)&quot;}
      {-log_file -type file -optional -description &quot;Optional message log file&quot;}
      {text -type string -multiple -description &quot;Multiple text lines to display&quot;}
   }
} {
<em>   puts &quot;display message:&quot;
   foreach var {mtype font level fg bg no_border log_file text} {
      if {[info exists $var]} {
         puts  &quot;  $var=[set $var]&quot;
      }
   }
</em>}</pre>
<p>A call of procedure that has been declared in this way will first invoke the TEPAM argument manager, before the procedure body is executed. The argument manager parses the provided arguments, validates them, completes them eventually with some default values, and makes them finally available to the procedure body as local variables. In case an argument is missing or has a wrong type, the argument manager generates an error message that explains the reason for the error.</p>
<p>As the example above shows, the TEPAM command <b class="cmd"><a href="../../../../index.html#procedure">procedure</a></b> accepts subcommand definitions as procedure name and allows defining much more information than just the argument list inside the procedure header. The procedure body on the other hand is identical between a command declared with <b class="cmd"><a href="../../../../index.html#proc">proc</a></b> and a command declared with <b class="cmd"><a href="../../../../index.html#procedure">procedure</a></b>.</p>
<p>The procedure header allows defining in addition to the arguments some procedure attributes, like a description, information concerning the return value, etc. This information is basically used for the automatic generation of comprehensive help and usage texts.</p>
<p>A list of argument definition statements assigned to the <i class="arg">-args</i> argument is defining the procedure arguments. Each argument definition statement starts with the argument name, optionally followed by some argument attributes.</p>
<p>Three types of arguments can be defined: Unnamed arguments, named arguments and flags. The distinction between the named and unnamed arguments is made by the first argument name character which is simply &quot;-&quot; for named arguments. A flag is defined as named argument that has the type  <em>none</em>.</p>
<p>Named and unnamed arguments are mandatory, unless they are declared with the <i class="arg">-optional</i> flag and unless they have a default value specified with the <i class="arg">-default</i> option. Named arguments and the last unnamed argument can have the attribute <i class="arg">-multiple</i>, which means that they can be defined multiple times. The expected argument data type is specified with the <i class="arg">-type</i> option. TEPAM defines a large set of standard data types which can easily be completed with application specific data types.</p>
<p>The argument declaration order has only an importance for unnamed arguments that are by default parsed after the named arguments (Tcl style). A variable allows changing this behavior in a way that unnamed arguments are parsed first, before the named arguments (Tk style).</p>
</div>
<div id="section4" class="doctools_section"><h2><a name="section4">PROCEDURE HELP</a></h2>
<p>The declared procedure can simply be called with the <i class="arg">-help</i> option to get the information about the usage of the procedure and its arguments:</p>
<pre class="doctools_example"><b class="cmd">display message</b> -help
<em>  -&gt;
NAME
      display message - Displays a simple message box
SYNOPSYS
      display message
            [-mtype &lt;mtype&gt;] :
               Message type, default: &quot;Warning&quot;, choices: {Info Warning Error}
            [-font &lt;font&gt;] :
               Message text font, type: font, default: Arial 10 italic
            [-level &lt;level&gt;] :
               Message level, type: integer, range: 1..10
            [-fg &lt;fg&gt;] :
               Message color, type: color, default: black
            [-bg &lt;bg&gt;] :
               Background color, type: color
            [-no_border ] :
               Use a splash window style (no border)
            [-log_file &lt;log_file&gt;] :
               Optional message log file, type: file
            &lt;text&gt; :
               Multiple text lines to display, type: string
DESCRIPTION
      This procedure allows displaying a configurable message box.</em></pre>
</div>
<div id="section5" class="doctools_section"><h2><a name="section5">PROCEDURE CALL</a></h2>
<p>The specified procedure can be called in many ways. The following listing shows some valid procedure calls:</p>
<pre class="doctools_example"><b class="cmd">display message</b> &quot;The document hasn't yet been saved!&quot;
<em>-&gt; display message:
     mtype=Warning
     font=Arial 10 italic
     fg=black
     no_border=0
     text={The document hasn't yet been saved!}</em>
<b class="cmd">display message</b> -fg red -bg black &quot;Please save first the document&quot;
<em>-&gt; display message:
     mtype=Warning
     font=Arial 10 italic
     fg=red
     bg=black
     no_border=0
     text={Please save first the document}</em>
<b class="cmd">display message</b> -mtype Error -no_border &quot;Why is here no border?&quot;
<em>-&gt; display message:
     mtype=Error
     font=Arial 10 italic
     fg=black
     no_border=1
     text={Why is here no border?}</em>
<b class="cmd">display message</b> -font {Courier 12} -level 10 \
   &quot;Is there enough space?&quot; &quot;Reduce otherwise the font size!&quot;
<em>-&gt; display message:
     mtype=Warning
     font=Courier 12
     level=10
     fg=black
     no_border=0
     text={Is there enough space?} {Reduce otherwise the font size!}</em></pre>
<p>The next lines show how wrong arguments are recognized. The <i class="arg">text</i> argument that is mandatory is missing in the first procedure call:</p>
<pre class="doctools_example"><b class="cmd">display message</b> -font {Courier 12}
<em>  -&gt; display message: Required argument is missing: text</em></pre>
<p>Only known arguments are accepted:</p>
<pre class="doctools_example"><b class="cmd">display message</b> -category warning Hello
<em>  -&gt; display message: Argument '-category' not known</em></pre>
<p>Argument types are automatically checked and an error message is generated in case the argument value has not the expected type:</p>
<pre class="doctools_example"><b class="cmd">display message</b> -fg MyColor &quot;Hello&quot;
<em>  -&gt; display message: Argument 'fg' requires type 'color'.  Provided value: 'MyColor'</em></pre>
<p>Selection choices have to be respected ...</p>
<pre class="doctools_example"><b class="cmd">display message</b> -mtype Fatal Hello
<em>  -&gt; display message: Argument (mtype) has to be one of the  following elements: Info, Warning, Error</em></pre>
<p>... as well as valid value ranges:</p>
<pre class="doctools_example"><b class="cmd">display message</b> -level 12 Hello
<em>  -&gt; display message: Argument (level) has to be between 1 and 10</em></pre>
</div>
<div id="section6" class="doctools_section"><h2><a name="section6">INTERACTIVE PROCEDURE CALLS</a></h2>
<p>The most intuitive way to call the procedure is using an form that allows specifying all arguments interactively. This form will automatically be generated if the declared procedure is called with the <i class="arg">-interactive</i> flag. To use this feature the Tk library has to be loaded.</p>
<pre class="doctools_example"><b class="cmd">display message</b> -interactive</pre>
<p>The generated form contains for each argument a data entry widget that is adapted to the argument type. Check buttons are used to specify flags, radio boxes for tiny choice lists, disjoint list boxes for larger choice lists and files, directories, fonts and colors can be selected with dedicated browsers.</p>
<p>After acknowledging the specified argument data via an OK button, the entered data are first validated, before the provided arguments are transformed into local variables and the procedure body is executed. In case the entered data are invalid, a message appears and the user can correct them until they are valid.</p>
<p>The procedure calls can optionally be logged in a variable. This is for example useful to get the command call lines of interactively called procedures.</p>
</div>
<div id="section7" class="doctools_section"><h2><a name="section7">FLEXIBLE ARGUMENT DIALOG BOX</a></h2>
<p>The form generator that creates in the previous example the argument dialog box for the interactive procedure call is also available for other purposes than for the definition of procedure arguments. If Tk has been loaded TEPAM provides and argument dialog box that allows creating complex parameter definition forms in a very efficient way.</p>
<p>The following example tries to illustrate the simplicity to create complex data entry forms. It creates an input mask that allows specifying a file to copy, a destination folder as well as a checkbox that allows specifying if an eventual existing file can be overwritten. Comfortable browsers can be used to select files and directories. And finally, the form offers also the possibility to accept and decline the selection. Here is the code snippet that is doing all this:</p>
<pre class="doctools_example"><b class="cmd"><a href="tepam_argument_dialogbox.html">tepam::argument_dialogbox</a></b> \
   <b class="cmd">-existingfile</b> {-label &quot;Source file&quot; -variable SourceFile} \
   <b class="cmd">-existingdirectory</b> {-label &quot;Destination folder&quot; -variable DestDir} \
   <b class="cmd">-checkbutton</b> {-label &quot;Overwrite existing file&quot; -variable Overwrite}</pre>
<p>The <b class="cmd">argument_dialogbox</b> returns <b class="const">ok</b> if the entered data are validated. It will return <b class="const">cancel</b> if the data entry has been canceled. After the validation of the entered data, the <b class="cmd">argument_dialogbox</b> defines all the specified variables with the entered data inside the calling context.</p>
<p>An <b class="cmd">argument_dialogbox</b> requires a pair of arguments for each variable that it has to handle. The first argument defines the entry widget type used to select the variable's value and the second one is a lists of attributes related to the variable and the entry widget.</p>
<p>Many entry widget types are available: Beside the simple generic entries, there are different kinds of list and combo boxes available, browsers for existing and new files and directories, check and radio boxes and buttons, as well as color and font pickers. If necessary, additional entry widgets can be defined.</p>
<p>The attribute list contains pairs of attribute names and attribute data. The primary attribute is <i class="arg">-variable</i> used to specify the variable in the calling context into which the entered data has to be stored. Another often used attribute is <i class="arg">-label</i> that allows adding a label to the data entry widget. Other attributes are available that allow specifying default values, the expected data types, valid data ranges, etc.</p>
<p>The next example of a more complex argument dialog box provides a good overview about the different available entry widget types and parameter attributes. The example contains also some formatting instructions like <i class="arg">-frame</i> and <i class="arg">-sep</i> which allows organizing the different entry widgets in frames and sections:</p>
<pre class="doctools_example">set ChoiceList {&quot;Choice 1&quot; &quot;Choice 2&quot; &quot;Choice 3&quot; &quot;Choice 4&quot; &quot;Choice 5&quot; &quot;Choice 6&quot;}
set Result [<b class="cmd"><a href="tepam_argument_dialogbox.html">tepam::argument_dialogbox</a></b> \
   <b class="cmd">-title</b> &quot;System configuration&quot; \
   <b class="cmd">-context</b> test_1 \
   <b class="cmd">-frame</b> {-label &quot;Entries&quot;} \
      <b class="cmd">-entry</b> {-label Entry1 -variable Entry1} \
      <b class="cmd">-entry</b> {-label Entry2 -variable Entry2 -default &quot;my default&quot;} \
   <b class="cmd">-frame</b> {-label &quot;Listbox &amp; combobox&quot;} \
      <b class="cmd">-listbox</b> {-label &quot;Listbox, single selection&quot; -variable Listbox1 \
                -choices {1 2 3 4 5 6 7 8} -default 1 -height 3} \
      <b class="cmd">-listbox</b> {-label &quot;Listbox, multiple selection&quot; -variable Listbox2
                -choicevariable ChoiceList -default {&quot;Choice 2&quot; &quot;Choice 3&quot;}
                -multiple_selection 1 -height 3} \
      <b class="cmd">-disjointlistbox</b> {-label &quot;Disjoined listbox&quot; -variable DisJntListbox
                        -choicevariable ChoiceList \
                        -default {&quot;Choice 3&quot; &quot;Choice 5&quot;} -height 3} \
      <b class="cmd">-combobox</b> {-label &quot;Combobox&quot; -variable Combobox \
                 -choices {1 2 3 4 5 6 7 8} -default 3} \
   <b class="cmd">-frame</b> {-label &quot;Checkbox, radiobox and checkbutton&quot;} \
      <b class="cmd">-checkbox</b> {-label Checkbox -variable Checkbox
                 -choices {bold italic underline} -choicelabels {Bold Italic Underline} \
                 -default italic} \
      <b class="cmd">-radiobox</b> {-label Radiobox -variable Radiobox
                 -choices {bold italic underline} -choicelabels {Bold Italic Underline} \
                 -default underline} \
      <b class="cmd">-checkbutton</b> {-label CheckButton -variable Checkbutton -default 1} \
   <b class="cmd">-frame</b> {-label &quot;Files &amp; directories&quot;} \
      <b class="cmd">-existingfile</b> {-label &quot;Input file&quot; -variable InputFile} \
      <b class="cmd">-file</b> {-label &quot;Output file&quot; -variable OutputFile} \
      <b class="cmd">-sep</b> {} \
      <b class="cmd">-existingdirectory</b> {-label &quot;Input directory&quot; -variable InputDirectory} \
      <b class="cmd">-directory</b> {-label &quot;Output irectory&quot; -variable OutputDirectory} \
   <b class="cmd">-frame</b> {-label &quot;Colors and fonts&quot;} \
      <b class="cmd">-color</b> {-label &quot;Background color&quot; -variable Color -default red} \
      <b class="cmd">-sep</b> {} \
      <b class="cmd">-font</b> {-label &quot;Font&quot; -variable Font -default {Courier 12 italic}}]</pre>
<p>The <b class="cmd">argument_dialogbox</b> defines all the specified variables with the entered data and returns <b class="const">ok</b> if the data have been validated via the Ok button. If the data entry is cancelled by activating the Cancel button, the <b class="cmd">argument_dialogbox</b> returns <b class="const">cancel</b>.</p>
<pre class="doctools_example">if {$Result==&quot;cancel&quot;} {
   puts &quot;Canceled&quot;
} else { # $Result==&quot;ok&quot;
   puts &quot;Arguments: &quot;
   foreach Var {
      Entry1 Entry2
      Listbox1 Listbox2 DisJntListbox
      Combobox Checkbox Radiobox Checkbutton
      InputFile OutputFile InputDirectory OutputDirectory
      Color Font
   } {
      puts &quot;  $Var: '[set $Var]'&quot;
   }
}
<em>-&gt; Arguments:
   Entry1: 'Hello, this is a trial'
   Entry2: 'my default'
   Listbox1: '1'
   Listbox2: '{Choice 2} {Choice 3}'
   DisJntListbox: '{Choice 3} {Choice 5}'
   Combobox: '3'
   Checkbox: 'italic'
   Radiobox: 'underline'
   Checkbutton: '1'
   InputFile: 'c:\tepam\in.txt'
   OutputFile: 'c:\tepam\out.txt'
   InputDirectory: 'c:\tepam\input'
   OutputDirectory: 'c:\tepam\output'
   Color: 'red'
   Font: 'Courier 12 italic'</em></pre>
</div>
<div id="see-also" class="doctools_section"><h2><a name="see-also">See Also</a></h2>
<p><a href="tepam_argument_dialogbox.html">tepam::argument_dialogbox(n)</a>, <a href="tepam_procedure.html">tepam::procedure(n)</a></p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#argument_integrity">argument integrity</a>, <a href="../../../../index.html#argument_validation">argument validation</a>, <a href="../../../../index.html#arguments">arguments</a>, <a href="../../../../index.html#entry_mask">entry mask</a>, <a href="../../../../index.html#parameter_entry_form">parameter entry form</a>, <a href="../../../../index.html#procedure">procedure</a>, <a href="../../../../index.html#subcommand">subcommand</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Procedures, arguments, parameters, options</p>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2009-2013, Andreas Drollinger</p>
</div>
</div></body></html>
